//
//  AYHUD.m
//  SuiXin
//
//  Created by mac on 2023/10/9.
//

#import "AYHUD.h"

@implementation AYHUD

#pragma mark - 自定义宽度
+(void)PopupWindowWith:(NSString *)info andTop:(CGFloat)top
{
    
    //添加View
    UIView *LBView = [[UIView alloc] init];
    LBView.backgroundColor = [UIColor colorWithRed:83 / 255.0 green:83 / 255.0 blue:83 / 255.0 alpha:1];
    LBView.layer.cornerRadius = 2.0f;
    //解决键盘遮挡toast
    [[AYTool lastWindow] addSubview:LBView];
    
    //    Log(@"--->%@",[UIApplication sharedApplication].windows.lastObject.subviews);
    
    //添加lable
    UILabel *lable = [[UILabel alloc] init];
    lable.font  = [UIFont systemFontOfSize:15];
    lable.text = info;
    lable.textColor = [UIColor whiteColor];
    lable.textAlignment = NSTextAlignmentCenter;
    //判断是否按照width设置宽度
    CGSize currentSize ;
    CGSize size = [info boundingRectWithSize:CGSizeMake(SCREEN_W - 30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    //    CGSize size = [RYDComputingSizeTool sizeWithString:info font:[UIFont systemFontOfSize:15 weight:0] maxSize:CGSizeMake(SCREEN_W - 30, MAXFLOAT)];
    if (size.height > 19) {//如果大于行高那就说明,是多行
        lable.numberOfLines = 0;
        currentSize  =  size;
    } else {
        
        size = [info boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
        currentSize = size;
    }
    [LBView addSubview:lable];
    
    
    LBView.frame = CGRectMake((SCREEN_W - (currentSize.width + 30)) * 0.5 , top,  currentSize.width + 30, currentSize.height + 14);
    
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.equalTo(@(currentSize.width + 4));
        make.height.equalTo(@(currentSize.height + 4));
        make.centerX.equalTo(LBView.mas_centerX);
        //        make.centerX.mas_equalTo(LBView.centerX).offset(0);
        make.top.equalTo(LBView.mas_top).offset(5);
    }];
    
    //三秒后自动消失
    if (LBView != nil) {
        [UIView animateWithDuration:3.0 animations:^{
            LBView.alpha = 0;
        } completion:^(BOOL finished) {
            [LBView removeFromSuperview];
        }];
    }
    
    
}

+(void)PopupWindowWith:(NSString *)info{
    
    [self PopupWindowWith:info andTop:SCREEN_H - 100];
}

+ (void)popStrokeToast:(NSString *)info{
    //    RYDStrokeLabel *strokeLabel = [RYDStrokeLabel new];
    //    strokeLabel.text = info;
    //    strokeLabel.textAlignment = NSTextAlignmentCenter;
    //    strokeLabel.backgroundColor = [UIColor clearColor];
    //    strokeLabel.frame = CGRectMake(100, 100, 100, 100);
    //    [strokeLabel sizeToFit];
    //    CGRect rect = strokeLabel.frame;
    //    strokeLabel.frame = CGRectMake((SCREEN_W - rect.size.width) / 2, SCREEN_H - 150, rect.size.width, rect.size.height);
    //    [[XKPublicTool lastWindow] addSubview:strokeLabel];
    //    [UIView animateWithDuration:5.0 animations:^{
    //        strokeLabel.alpha = 0;
    //    } completion:^(BOOL finished) {
    //        [strokeLabel removeFromSuperview];
    //    }];
}

@end
